import React from 'react';
import { Button ,Table } from 'antd';
import Req from '../../../api';
class GoodsComm extends React.Component {
  constructor(props) {
    super(props);
    this.state={
      data: [],
      pagination: {
        current: 1,
        pageSize: 4,
      },
      loading: false
    }
  }
  const
  columns = [
    {
      title: 'ID',
      dataIndex: 'id',
    },
    {
      title: '抽奖名称',
      dataIndex: 'name',
    },
    {
      title: '活动日期',
      render: (row)=>{
        return (
            <div>
              <div>{row.startdate}</div>
              <div>{row.enddate}</div>
            </div>
        )
      }
    },
    // {
    //   title: '首页推荐',
    //   dataIndex: 'recommend',
    // },
    {
      title: '状态',
      dataIndex: 'state',
      render:(state)=>(
          state == 1 ? "尚未开始" : state == 2 ? "进行中" : "已结束"
      )
    },
    {
      title: '操作',
      dataIndex: 'option',
      render:()=>(
          <div>
            <Button type="link">查看</Button>
            <Button type="link">修改</Button>
            <Button type="link" danger>删除</Button>
          </div>
      )
    }
  ];
  componentDidMount() {
    this.getData();
  }
  getData = function () {
    this.setState({
      loading: true
    })
    Req.luckShow().then(res=>{
      console.log(res);
      console.log(res.data)
      this.setState({
        data: res.data,
        loading: false
      })
    }).catch(err=>{
      console.log(err)
    })
  }
  handleTableChange = (pagination) => {
    this.getData();
  };
  render() {
    const { data, pagination, loading } = this.state;
    return (
        <Table
            columns={this.columns}
            dataSource={data}
            rowKey={(record) => `complete${record.id}`}
            pagination={pagination}
            loading={loading}
            onChange={this.handleTableChange}
        />
    );
  }
}
export default GoodsComm